<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="./css/index.css">
</head>
<body>
    <div id="wrapBg">
        <div id="headTittle">
        <img src="./img/bird0.png" alt="" id=headBird>
        </div>
        <button id="startBtn"></button>
        <div id="gressLand1"></div>
        <div id="gressLand2"></div>
    </div>
    <script src="./js/bird.js"></script>
    <script src="./js/block.js"></script>
    <script>
    var jsHeadBird=document.getElementById('headBird')
    var jswrapBg=document.getElementById('wrapBg')
    // 循环控制headTittle容器的top值的加减
    var jsHeadTittle=document.getElementById('headTittle')//获取headTittle这个id
    var Y=3 // 标题摆动的幅度
    var headWaveTimer=setInterval(headwave,200)//定时器
    function headwave(){
        Y=Y*-1
     jsHeadTittle.style.top=jsHeadTittle.offsetTop+Y+'px'
     //翅膀煽动
     if(Y>0){
        jsHeadBird.src="./img/bird1.png"
     }else{
        jsHeadBird.src="./img/bird0.png"
     }
    }

    //草地
    var jsGRessLand1=document.getElementById('gressLand1')
    var jsGRessLand2=document.getElementById('gressLand2')
    setInterval(LandRun,30)//草地移动
    function LandRun(){
        if(jsGRessLand1.offsetLeft<=-343){
            jsGRessLand1.style.left=343+'px'
        }
        if(jsGRessLand2.offsetLeft<=-343){
            jsGRessLand2.style.left=343+'px'
        }
        jsGRessLand1.style.left=jsGRessLand1.offsetLeft-3+'px'
        jsGRessLand2.style.left=jsGRessLand2.offsetLeft-3+'px'
    }
    
    //开始游戏
    var jsStartBtn = document.getElementById('startBtn')
    jsStartBtn.onclick=function(){
        jsHeadTittle.style.display='none'//隐藏标题
        clearInterval(headWaveTimer) // 清除定时器
        jsStartBtn.style.display='none'
        //出现一只小鸟
       bird.showBird(jswrapBg) 
       bird.flyBird()
       bird.wingWave()

       jswrapBg.onclick = function() {
           bird.fallSpeed = -8
       }

       //出现管道
       var b = new Block()
       b.createBlock() 
       //管道移动
       setInterval(BlockRun,300)
       function BlockRun() {
           if(b.upDivWrap.offsetLeft<=0){
               b.upDivWrap.style.left=343+'px'
           }
           b.upDivWrap.style.left = b.upDivWrap.offsetLeft-50 + 'px'
       }
    }
    </script>
</body>
</html>